package com.zhika.zishi.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/13.
 */
public class ChannelFragmentAdpter extends FragmentStatePagerAdapter {

    private ArrayList<Fragment> fragmentList;

    private ArrayList<String> tabList;

    public ChannelFragmentAdpter(FragmentManager fragmentManager,ArrayList<Fragment> fragmentList,ArrayList<String> tabList){
        super(fragmentManager);
        this.fragmentList = fragmentList;
        this.tabList =tabList;
    }

    @Override
    public Fragment getItem(int i) {
        int newPosition;
        if (i>=0){
            newPosition = (i+60)%6;
        }else {
            newPosition = (-i)%6;
        }

        switch (newPosition){
            case 0:
               return fragmentList.get(0);
            case 1:
                return fragmentList.get(1);
            case 2:
                return fragmentList.get(2);
            case 3:
                return fragmentList.get(3);
            case 4:
                return fragmentList.get(4);
            case 5:
                return fragmentList.get(5);
        }
        return null;
    }

    @Override
    public int getCount() {
        return 6000;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        int newPosition;
        if (position>=0){
            newPosition = (position+60)%6;
        }else {
            newPosition = (-position)%6;
        }

        switch (newPosition){
            case 0:
                return tabList.get(0);
            case 1:
                return tabList.get(1);
            case 2:
                return tabList.get(2);
            case 3:
                return tabList.get(3);
            case 4:
                return tabList.get(4);
            case 5:
                return tabList.get(5);
        }

        return null;
    }
}
